local test = UnitTest:New("09DongleTimer")
local Dongle = DongleStub("Dongle-1.0")

local function TimerFunc(name, scheduleTime)
	Dongle:PrintF("Timer: %s, TimeToTrigger: %f", name, GetTime() - scheduleTime)
end

local function TimeRemainingClose(dongle, name, seconds)
	local scheduled, remaining = dongle:IsTimerScheduled(name)
	if not remaining then return false end
	return math.abs(remaining - seconds) < 0.01
end

function test:dongle_schedule_timer_multiple()
	local ob = Dongle:New("Omicron-Alpha")
	ob:ScheduleTimer("1", TimerFunc, 1, GetTime())
	ob:ScheduleTimer("6", TimerFunc, 6, GetTime())
	ob:ScheduleRepeatingTimer("r2", TimerFunc, 2, GetTime())
	ob:ScheduleTimer("5", TimerFunc, 5, GetTime())
	ob:ScheduleTimer("10", TimerFunc, 10, GetTime())
	ob:ScheduleTimer("3", TimerFunc, 3, GetTime())
	ob:ScheduleTimer("4", TimerFunc, 4, GetTime())
	ob:ScheduleTimer("7", TimerFunc, 7, GetTime())
	ob:ScheduleTimer("8", TimerFunc, 8, GetTime())
	ob:ScheduleTimer("9", TimerFunc, 9, GetTime())
	ob:CancelTimer("5")
	assert(not ob:IsTimerScheduled("5"))
	assert(ob:IsTimerScheduled("1") and TimeRemainingClose(ob, "1", 1))
	assert(ob:IsTimerScheduled("r2") and TimeRemainingClose(ob, "r2", 2))
	assert(ob:IsTimerScheduled("3") and TimeRemainingClose(ob, "3", 3))
	assert(ob:IsTimerScheduled("4") and TimeRemainingClose(ob, "4", 4))
	assert(ob:IsTimerScheduled("6") and TimeRemainingClose(ob, "6", 6))
	assert(ob:IsTimerScheduled("7") and TimeRemainingClose(ob, "7", 7))
	assert(ob:IsTimerScheduled("8") and TimeRemainingClose(ob, "8", 8))
	assert(ob:IsTimerScheduled("9") and TimeRemainingClose(ob, "9", 9))
	assert(ob:IsTimerScheduled("10") and TimeRemainingClose(ob, "10", 10))
end

test:Run()
